package model.playable;
import model.command.*;
import model.item.ItemUser;
import model.map.*;
import java.util.*;
import model.visibility.*;
import model.mapping.*;

public abstract class Playable implements ItemUser, BasicCommandable
{
	private PlayableUser player;
	private int idNumber;
	private int upkeep;
	private int influenceRadius;
	private int visibilityRadius;
	private LinkedList<Command> commandQueue;
	private LinkedList<Command> commandsPossibleList;
	private int currentPossibleCommandPosition;
	private boolean isInStandBy;
	private boolean isPoweredDown;

	public PlayableUser getPlayer()
	{
		return player;
	}
	
	public void setPlayer(PlayableUser player)
	{
		this.player = player;
	}
	
	public int getIdNumber()
	{
		return idNumber;
	}
	
	public void setIdNumber(int idNumber)
	{
		this.idNumber = idNumber;
	}
	
	public int getUpkeep()
	{
		return upkeep;
	}
	
	public void setUpkeep(int upkeep)
	{
		this.upkeep = upkeep;
	}
	
	public int getInfluenceRadius()
	{
		return influenceRadius;
	}
	
	public void setInfluenceRadius(int influenceRadius)
	{
		this.influenceRadius = influenceRadius;
	}
	public int getVisibilityRadius()
	{
		return visibilityRadius;
	}
	
	public void setVisibilityRadius(int visibilityRadius)
	{
		this.visibilityRadius = visibilityRadius;
	}
	
	public LinkedList<Command> getCommandQueue()
	{
		return commandQueue;
	}
	
	public void setCommandQueue(LinkedList<Command> commandQueue)
	{
		this.commandQueue = commandQueue;
	}
	
	public LinkedList<Command> getCommandsPossibleList()
	{
		return commandsPossibleList;
	}
	
	public void setCommandsPossibleList(LinkedList<Command> commandsPossibleList)
	{
		this.commandsPossibleList = commandsPossibleList;
	}
	
	public int getCurrentPossibleCommandPosition()
	{
		return currentPossibleCommandPosition;
	}
	
	public void setCurrentPossibleCommandPosition(int currentPossibleCommandPosition)
	{
		this.currentPossibleCommandPosition = currentPossibleCommandPosition;
	}
	
	public boolean getIsInStandBy()
	{
		return isInStandBy;
	}
	
	public void setIsInStandBy(boolean isInStandBy)
	{
		this.isInStandBy = isInStandBy;
	}
	
	public boolean getIsPoweredDown()
	{
		return isPoweredDown;
	}
	
	public void setIsPoweredDown(boolean isPoweredDown)
	{
		this.isPoweredDown = isPoweredDown;
	}
	
	public void addUpkeep(int amount)
	{
	}
	
	public void incrementUpkeep(int increment)
	{
		upkeep += increment;
	}
	
	public void incrementInfluenceRadius(int increment)
	{
		influenceRadius += increment;
	}
	
	public void incrementVisibilityRadius(int increment)
	{
		visibilityRadius += increment;
	}
	
	public void addToCommandQueue(Command command)
	{
		//if(checkCommandsPossibleList(command) && !getIsPoweredDown())
		//{
		if(!getIsPoweredDown())
		{
			setIsInStandBy(false);
			commandQueue.add(command);
		}
		else
		{
			getCommandQueue().add(new Standby(this));
		}
	}
	
	public void executeCommand()
	{
		if(!commandQueue.isEmpty())
		{
			getCommandFromQueue().executeCommand();
		}
	}
	
	public Command getCommandFromQueue()
	{
		if(getCommandQueue().size() != 0)
		{
			return commandQueue.removeFirst();
		}
			return null;
	}
	
	public void clearCommandQueue()
	{
		commandQueue = new LinkedList<Command>();
	}
	
	public LinkedList<Command> createCommandPossibleList()
	{
		return null;
	}
	
	public void addToCommandsPossibleList(Command command)
	{
		commandQueue.add(command);
	}
	
	public boolean checkCommandsPossibleList(Command command)
	{
		return commandsPossibleList.contains(command);
	}
	
	public Command getCurrentPossibleCommand()
	{
		return commandsPossibleList.get(currentPossibleCommandPosition);
	}
	
	public Command getNextPossibleCommand()
	{
		if(currentPossibleCommandPosition == commandsPossibleList.size() -1)
		{
			currentPossibleCommandPosition = 0;
		}
		else
		{
			currentPossibleCommandPosition += 1;
		}
		return commandsPossibleList.get(currentPossibleCommandPosition);
	}
	
	public Command getPreviousPossibleCommand()
	{
		if(currentPossibleCommandPosition == 0)
		{
			currentPossibleCommandPosition = commandsPossibleList.size()-1;
		}
		else
		{
			currentPossibleCommandPosition -= 1;
		}
		return commandsPossibleList.get(currentPossibleCommandPosition);
	}
	
	public void powerUp()
	{
	}
	
	public void powerDown()
	{
	}
	
	public void decommission()
	{
	}
	
	public void standBy()
	{
	}
	
	public void takeDamage(int i)
	{
	}
	
	public void heal(int i)
	{
	}
	
	public void giveFood(int i)
	{
		player.addFood(i);
	}
	
	public void giveEnergy(int i)
	{
		player.addEnergy(i);
	}
	
	public void giveOre(int i)
	{
		player.addOre(i);
	}
	
	public GameTile getLocation()
	{
		return null;
	}
	
	public void accept(PlayableVisitor pv)
	{
	}
}